#include "OAuthBaseInfo.h"
#include <sstream>
#include <ctime>
#include <algorithm>

OAuthBaseInfo::OAuthBaseInfo(void)
{
	stringstream ss;
	ss << time(0);
	string timestamp;
	ss >> timestamp;

	_oauth["oauth_consumer_key"] = "";
	_oauth["oauth_nonce"] = "abcdfefd";
	_oauth["oauth_signature_method"] = "HMAC-SHA1";
	_oauth["oauth_timestamp"] = timestamp;//"1320118351";
	_oauth["oauth_token"] = "";
	_oauth["oauth_version"] = "1.0";

	oauth_token_secret = "";
	oauth_consumer_secret = "";


	_all = _oauth;
}

OAuthBaseInfo::~OAuthBaseInfo(void)
{
}

void OAuthBaseInfo::setUrl(std::string name, std::string value)
{
	_all[name] = value;
}

string OAuthBaseInfo::getBaseString()
{
	string s("");
	map<string, string>::iterator pItr;
	for(pItr = _all.begin(); pItr != _all.end(); ++pItr){
		if(!s.empty()){
			s += "%26" ;
		}
		s += pItr->first + "%3D" + pItr->second;
	}

	return s;
}

string OAuthBaseInfo::getContent()
{
	string s("");
	map<string, string>::iterator pItr;
	for(pItr = _oauth.begin(); pItr != _oauth.end(); ++pItr){
		s += pItr->first + "=\"" + pItr->second + "\",";
	}

	return s;
}